﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Core.Exceptions
{
    /// <summary>
    /// 支付异常帮助
    /// </summary>
    public static class PayExceptionUtils
    {
        /// <summary>
        /// 检查非空
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="value">值</param>
        /// <param name="argName">参数名称</param>
        public static T CheckNotNull<T>(T value, string argName) where T : class
        {
            if (value == null)
            {
                throw new PayValidationException(argName + " 为 null");
            }
            return value;
        }

        /// <summary>
        /// 检查非空和非空白对象
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="argName">参数名称</param>
        /// <returns></returns>
        public static string CheckNotNullOrNotWhiteSpace(string value, string argName)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new PayValidationException(argName + " 为 null 或空白值。");
            }
            return value;
        }

        /// <summary>
        /// 抛出验证性异常
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="innerException">源异常</param>
        /// <returns></returns>
        public static PayValidationException ThrowPayValidationException(string message, Exception innerException = null)
        {
            throw new PayValidationException(message, innerException);
        }

        /// <summary>
        /// 抛出系统异常
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="innerException">源异常</param>
        /// <returns></returns>
        public static PaySystemException ThrowPaySystemException(string message, Exception innerException = null)
        {
            throw new PaySystemException(message, innerException);
        }

        /// <summary>
        /// 抛出数据格式异常
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="innerException">源异常</param>
        /// <returns></returns>
        public static PayDataFormatException ThrowPayDataFormatException(string message, Exception innerException = null)
        {
            throw new PayDataFormatException(message, innerException);
        }

        /// <summary>
        /// 抛出异常
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="innerException">源异常</param>
        /// <returns></returns>
        public static PayException ThrowPayException(string message, Exception innerException = null)
        {
            throw new PayException(message, innerException);
        }

        /// <summary>
        /// 抛出签名异常
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static PaySignException ThrowPaySignException(string message)
        {
            throw new PaySignException(message);
        }

    }
}
